*ANALYSIS CODE FOR PRATIWI ET AL. INDONESIA UHC PAPER
clear 
set more off

global root "/Users/elizabethpisani/Dropbox/indon_uhc/"

global master "$root/master_data"
global tempfiles "$root/tempfiles"
global results "$root/results/2018"
global data "$root/analysis_data/2018"

cd $root


log using "$results/pratiwi_analysis.log", replace

**************************
*DESCRIBE DATASET (DATA TABLE 1)
**************************
*AVERAGE N HOUSEHOLDS/VILLAGES/DISTRICTS PER YEAR
use "$data/hh/susenas_2018.dta", clear
tab year, m
use "$data/hh/podesanalysis.dta", clear
tab year, m
use "$data/district/ipkm_kab.dta", clear
tab year, m
use "$data/district/bpjs_kab.dta", clear
tab year, m

**************************
*BASIC DESCRIPTIVE VARIABLES: TABLE 1
**************************

use "$data/region/all_nomaps_reg.dta", clear

*GENERAL DEMOGRAPHIC VARIABLES (MEDIAN EXPENDITURE)
list region population usd_exp_cap, noobs

*HEALTH STATUS and SERVICE USE
list region ipkm_healthneed symptoms_1mo outpatient_1mo treated_op inpatient_1yr, noobs

*INSURANCE and MEDIAN HEALTH EXPENDITURE
list region pct_bpjs_insured_infl insurance insurance_jkn_all usd_health_exp_1yr_hh, noobs

*NATIONAL TOTALS
use "$data/hh/susenas_ipkm_podes_bpjs_individual.dta", clear
collapse (mean) symptoms_1mo outpatient_1mo treated_op inpatient_1yr insurance insurance_jkn_all  (p50) exp_cap health_exp_1yr_hh [pweight=wert] 
local expenditure exp_cap health_exp_1yr_hh
foreach x of local expenditure {
	gen usd_`x' = (`x'/13760)
	local lbl : var label `x'
	lab var usd_`x'  "US$ `lbl', at March 2018 exchange rate'"
}

list

use "$data/district/bpjs_kab.dta", clear
collapse (sum) bpjs_total_insured_infl population
gen pct_bpjs_insured_infl = (bpjs_total_insured_infl/population)*100
tab pct_bpjs_insured_infl


use "$data/district/ipkm_kab.dta", clear
tabstat ipkm_healthneed // Note the IPKM is already weighted to be nationally representative


**************************
*INSURANCE COVERAGE, FROM SUSENAS: TABLE 2
**************************


use "$data/hh/susenas_2018.dta",clear

tab region insurance_type [aweight=wert], row nofreq
tab region insurance_source [aweight=wert], row nofreq
tab insurance_multiple [aw=wert]
tab SE_nonhealth insurance_source [aweight=wert], row nofreq


********************************
*SERVICE AVAILABILITY & USE: TABLE 3
********************************

*NATIONAL TOTALS
use "$data/hh/podesanalysis.dta", clear
tabstat podes_hospitalaccess podes_inpatient_primary_only podes_puskesmas_access podes_zero_access_binary, by (region) f(%9.3fc)



clear
use "$data/hh/susenas_2018.dta",clear

tabstat inpatient_1yr [aw=wert], by (region) f(%9.3fc)

/*
*ADDITIONAL ANALYSES LOOKING AT SERVICE USE BY INSURANCE STATUS AND HOUSEHOLD WEALTH
tab insurance inpatient_1yr [aw=wert], row
tab insurance inpatient_1yr, row chi2

bysort insurance: tab SE_nonhealth inpatient_1yr [aw=wert], row
*/
********************************
*INSURANCE USE: TABLE 2
********************************

 use "$data/region/all_nomaps_reg.dta", clear

*tabstat  usd_bpjs_perclaim_in usd_bpjs_perclaim_out usd_bpjs_claim_in_pc usd_bpjs_claim_out_pc bpjs_cases_in_pc bpjs_cases_out_pc, by(region) s(mean) f(%9.2fc)

list region usd_bpjs_perclaim_in usd_bpjs_perclaim_out usd_bpjs_claim_in_pc usd_bpjs_claim_out_pc bpjs_cases_in_pc bpjs_cases_out_pc, noobs
tabstat  usd_bpjs_perclaim_in usd_bpjs_perclaim_out usd_bpjs_claim_in_pc usd_bpjs_claim_out_pc bpjs_cases_in_pc bpjs_cases_out_pc, s(mean) f(%9.2fc)

********************************
*OOP: TABLE 2
********************************
clear
use "$data/hh/susenas_2018.dta",clear

*MEDIAN 00P SPENDING ON HEALTH PER CAP, ALL
table region insurance [aw=wert], c(p50 usd_health_exp_1yr_hh_cap) f(%9.2fc) // US$ MEDIAN, BY ANY INSURANCE

*BY INSURANCE STATUS, PCT WHO GOT INPATIENT CARE WITH NO OOP SPENDING
bysort insurance: tab region anyoop_inpatient if inpatient_1yr ==1, row chi2
bysort insurance: tab region anyoop_inpatient if inpatient_1yr ==1 [aw=wert], row  // weighted, for reporting

*COST OF INPATIENT CARE, FOR THOSE WHO HAD OOP ON INPATIENT CARE
tabstat usd_inpatient_ave1yr_realcap [aw=wert] if inpatient_1yr ==1 & anyoop_inpatient==1, by(region) stats(p25 p50 p75 mean) f(%12.2fc) // US$
bysort insurance: tabstat usd_inpatient_ave1yr_realcap [aw=wert] if inpatient_1yr ==1 & anyoop_inpatient==1, by(region) stats(p25 p50 p75 mean) f(%12.2fc) // US$

********************************
*FIGURE 2, COMPARING BURDEN OF OOP ON INPATIENT BY SES AND INSURANCE STATUS.
*NB, SES INDICATOR IS NON-HEALTH HOUSEHOLD CONSUMPTION PER CAPITA 
********************************

bysort insurance: tab SE_nonhealth cat_inpatient_oop_nonhealth [aw=wert], row nofreq // FOR 100% GRAPH
bysort insurance: tab SE_nonhealth cat_inpatient_oop_nonhealth [aw=wert] // FOR ABSOLUTE GRAPH

*************************
*MAPS: SUPPLEMENTARY FIGURE B (MONOCHROME, THEN POLYCHROME)
*************************

*MAPS, MONOCHROME*

*FIGURE Da: MAP SHOWING REGIONS

clear
use "analysis_data/2018/district/2018_mapping_kab.dta", clear
gen mapping_region = region
recode mapping_region 1=4 2=3 3=2 4=1
lab def mapping_region 4 "Java & Bali" 3 "Sumatera & Islands" 2 "NTB, Kalimantan, Sulawesi" 1 "NTT, Malukus, Papua"
lab val mapping_region mapping_region
spmap mapping_region using "maps/district2017_c",id(id) fcol(Reds) clmethod(unique) 
graph export "results/2018/Fig4a_map_regions.png", replace

*FIGURE Db: MAP BY QUINTILES OF HEALTH NEED
*
spmap ipkm_healthneed using "maps/district2017_c", id(id) fcol(Reds) clmethod(quantile) clnumber(5)
graph export "results/2018/Fig4b_map_health_need_quitniles.png", replace

*FIGURE Dc: MAP BY QUINTILES OF INSURANCE COVERAGE
spmap insurance using "maps/district2017_c", id(id) fcol(Reds) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4c_map_insurance_quitniles.png", replace

*FIGURE Dd: MAP BY QUINTILES OF ACCESS TO INPATIENT SERVICES
spmap podes_inpatientaccess using "maps/district2017_c", id(id) fcol(Reds) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4d_map_inpatient_access_quintiles.png", replace

*FIGURE De: MAP BY QUINTILES OF USE OF INPATIENT SERVICES IN PREVIOUS 12 MONTHS
spmap inpatient_1yr using "maps/district2017_c", id(id) fcol(Reds) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4e_map_inpatient_use_quitniles.png", replace

*FIGURE Df: USD ANNUAL INSURANCE CLAIMS PER INSURED PERSON (BPJS REPORTS), INPATIENT
gen usd_bpjs_claim_in_perperson = usd_bpjs_claim_in_pc/1000
format usd_bpjs_claim_in_perperson %9.2fc
spmap usd_bpjs_claim_in_perperson using "maps/district2017_c", id(id) fcol(Reds)  ndfcolor(gray) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4f_map_inpatient_claims_quitniles.png", replace

*FIGURE Dg: MEDIAN USD OOP SPENDING, INPATIENT, OF THOSE REPORTING INPATIENT CARE
*NB IN THREE "NO DATA" KABUPATEN, NO RESPONDENTS REPORTED INPATIENT CARE. IN THIS CASE, 45% REPORT ZERO SPENDING, RESULTING IN ONLY 4 COLOUR GRADATIONS
spmap usd_inpatient_ave1yr_realcap using "maps/district2017_c", id(id) fcol(Reds)  ndfcolor(gray) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4g_map_inpatient_oop_quitniles.png", replace


*MAPS, POLYCHROME*

*FIGURE Da: MAP SHOWING REGIONS

clear
use "analysis_data/2018/district/2018_mapping_kab.dta", clear
gen mapping_region = region
recode mapping_region 1=4 2=3 3=2 4=1
lab def mapping_region 4 "Java & Bali" 3 "Sumatera & Islands" 2 "NTB, Kalimantan, Sulawesi" 1 "NTT, Malukus, Papua"
lab val mapping_region mapping_region
spmap mapping_region using "maps/district2017_c",id(id) fcol(red yellow green blue) clmethod(unique) 
graph export "results/2018/Fig4a_map_regions_polychrome.png", replace

*FIGURE Db: MAP BY QUINTILES OF HEALTH NEED
spmap ipkm_healthneed using "maps/district2017_c", id(id) fcol(blue green yellow orange red) clmethod(quantile) clnumber(5)
graph export "results/2018/Fig4b_map_health_need_quitniles_polychrome.png", replace

*FIGURE Dc: MAP BY QUINTILES OF INSURANCE COVERAGE
spmap insurance using "maps/district2017_c", id(id) fcol(red orange yellow green blue) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4c_map_insurance_quitniles_polychrome.png", replace

*FIGURE Dd: MAP BY QUINTILES OF ACCESS TO INPATIENT SERVICES
spmap podes_inpatientaccess using "maps/district2017_c", id(id) fcol(red orange yellow green blue) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4d_map_inpatient_access_quintiles_polychrome.png", replace

*FIGURE De: MAP BY QUINTILES OF USE OF INPATIENT SERVICES IN PREVIOUS 12 MONTHS
spmap inpatient_1yr using "maps/district2017_c", id(id) fcol(red orange yellow green blue) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4e_map_inpatient_use_quitniles_polychrome.png", replace

*FIGURE Df: USD ANNUAL INSURANCE CLAIMS PER INSURED PERSON (BPJS REPORTS), INPATIENT
gen usd_bpjs_claim_in_perperson = usd_bpjs_claim_in_pc/1000
format usd_bpjs_claim_in_perperson %9.2fc
spmap usd_bpjs_claim_in_perperson using "maps/district2017_c", id(id) fcol(red orange yellow green blue)  ndfcolor(gray) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4f_map_inpatient_claims_quitniles_polychrome.png", replace

*FIGURE Dg: MEDIAN USD OOP SPENDING, INPATIENT, OF THOSE REPORTING INPATIENT CARE
*NB IN THREE "NO DATA" KABUPATEN, NO RESPONDENTS REPORTED INPATIENT CARE. IN THIS CASE, 45% REPORT ZERO SPENDING, RESULTING IN ONLY 4 COLOUR GRADATIONS
spmap usd_inpatient_ave1yr_realcap using "maps/district2017_c", id(id) fcol(blue yellow orange red)  ndfcolor(gray) clmethod(quantile) clnumber(5) 
graph export "results/2018/Fig4g_map_inpatient_oop_quitniles_polychrome.png", replace



******************
*REGRESSIONS, FOLLOWING THE MODEL
*INDIVIDUAL LEVEL OUTCOMES (SERVICE USE, OOP) USE INDIVIDUAL DATA; DISTRICT LEVEL OUTCOMES USE DISRICT AVERAGES
*******************

*log using "$results/regressions.txt", text replace
***********
*LEXICON OF VARIABLES USED IN REGRESSIONS:
***********

*DEPENDENT VARIABLES:
*treat_any: inpatient care last 12 months and/or outpatient care last month, susenas, individual. yes/no
*inpatient_1yr: inpatient care last 12 months, susenas, individual, yes/no
*usd_inpatient_ave1yr_cap_all: if the person had inpatient care last year, total household spending on inpatient care last year divided by total hh members reporting inpatient care last year, else 0. susenas, individual, converted into US$ at exchange rate in month of survey
*usd_health_exp_1yr_hh_cap: total household spending on health (excluding transport and premiums) in last 12 months, divied by number of hh members. susenas, individual, converted into US$ at exchange rate in month of survey
*usd_bpjs_claim_total_realpc: amount of claims paid by bpjs for the year, divided by the total population of the district, converted into US$ at av exchange rate for year. bpjs, kabupaten level 

*INDEPENDENT VARIABLES:
*cat_healthneed: quintile of health need index. Riskesdas, kabupaten level.
*insurance: Individual has health insurance from any source, susenas, self-reported, individual
*cat_insurance: % of district population with health insurance, in quintiles. derived from susenas individual, but calculated at kabupaten level
*cat_pctzero_use: % of villages in district with no easy access to any health services, categorised. Podes, derived from villages level data but calculated at kabupaten level 
*cat_noinpatient: % of villages in district with no easy access to any inpatient services, categorised. Podes, derived from villages level data but calculated at kabupaten level 
*SE_nonhealth: quintile of per capita household consumption excluding oop on health, susenas, individual


*NOTE THAT FOR OUTPATIENT SERVICES, SUSENAS HAS A FILTER QUESTION ABOUT SYMPTOMS IN THE LAST MONTH, AND ONLY ASKS ABOUT USE IF RESPONDENT REPORTS SYMPTOMS, SO ANY ANALYSES OF OUTPATIENT USE MUST BE RESTRICTED TO THOSE REPORTING SYMPTOMS. HOWEVER, OUTPATIENT SPENDING MEASURES ARE ASKED OF EVERYONE

*********
*LOG NOTE: RESULTS OF STEPS 1 AND 2 ARE NOT SHOWN IN PAPER
*********
*STEP ONE: IS LOWER HEALTH NEED ASSOCIATED WITH LOWER USE OF SERVICES AND OOP?
use "$data/hh/susenas_ipkm_podes_bpjs_individual.dta", clear
logit inpatient_1yr i.cat_healthneed [pw=fwt], or // USE OF INPATIENT SERVICES
regress usd_inpatient_ave1yr_cap_all i.cat_healthneed [pw=fwt] //INPATIENT SPENDING PER POPULATION 
logit treated_op i.cat_healthneed [pw=fwt], or // USE OF OUTPATIENT SERVICES, OF THOSE REPORTING SYMPTOMS
regress usd_outpatient_ave1mo_cap i.cat_healthneed [pw=fwt] //OUTPATIENT SPENDING PER POPULATION 
regress usd_health_exp_1yr_hh_cap i.cat_healthneed [pw=fwt] // ALL OOP HEALTH SPENDING PER POPULATION


*STEP TWO: DOES INSURANCE STATUS REDUCE DIFFERENCE IN USE OF SERVICES AND OOP?
use "$data/hh/susenas_ipkm_podes_bpjs_individual.dta", clear
logit inpatient_1yr i.cat_healthneed i.insurance [pw=fwt], or // USE OF INPATIENT SERVICES
logit treated_op i.cat_healthneed i.insurance [pw=fwt], or // USE OF OUTPATIENT SERVICES, OF THOSE REPORTING SYMPTOMS
regress usd_inpatient_ave1yr_cap_all i.cat_healthneed i.insurance [pw=fwt] //INPATIENT SPENDING PER POPULATION 
regress usd_outpatient_ave1mo_cap i.cat_healthneed i.insurance [pw=fwt] //OUTPATIENT SPENDING PER POPULATION
regress usd_health_exp_1yr_hh_cap i.cat_healthneed i.insurance [pw=fwt] // ALL OOP HEALTH SPENDING PER POPULATION

*****************
*TABLE 4: RESULTS OF FULL REGRESSION MODEL WITHOUT ECONOMIC STATUS
*****************

*STEP THREE: DOES ADDITION OF ACCESS TO HEALTH SERVICES FURTHER REDUCE DIFFERENCE IN EXPECTED RELATIONSHIP BETWEEN HEALTH NEED & USE OF SERVICES?
*NOTE WE ARE HERE USING MOST APPROPRIATE ACCESS MEASURE FOR EACH REGRESSION
use "$data/hh/susenas_ipkm_podes_bpjs_individual.dta", clear
logit inpatient_1yr i.cat_healthneed i.insurance i.cat_noinpatient [pw=fwt], or // USE OF INPATIENT SERVICES
logit treated_op i.cat_healthneed i.insurance i.cat_pctzero_use [pw=fwt], or // USE OF OUTPATIENT SERVICES, OF THOSE REPORTING SYMPTOMS
regress usd_inpatient_ave1yr_cap_all i.cat_healthneed i.insurance i.cat_noinpatient [pw=fwt] //INPATIENT SPENDING PER POPULATION 
regress usd_outpatient_ave1mo_cap i.cat_healthneed i.insurance i.cat_pctzero_use [pw=fwt] //OUTPATIENT SPENDING PER POPULATION
regress usd_health_exp_1yr_hh_cap i.cat_healthneed i.insurance i.cat_pctzero_use [pw=fwt] // ALL OOP HEALTH SPENDING PER POPULATION

*****************
*TABLE 5: RESULTS OF FULL REGRESSION MODEL WITH ECONOMIC STATUS
*****************

*FINAL STEP: ADD SOCIO-ECONOMIC STATUS,(I.E. QUINTILES OF PER CAPITA NON-HEALTH CONSUMPTION)
use "$data/hh/susenas_ipkm_podes_bpjs_individual.dta", clear
logit inpatient_1yr i.cat_healthneed i.insurance i.cat_noinpatient i.SE_nonhealth [pw=fwt], or // USE OF INPATIENT SERVICES
logit treated_op i.cat_healthneed i.insurance i.cat_pctzero_use i.SE_nonhealth [pw=fwt], or // USE OF OUTPATIENT SERVICES, OF THOSE REPORTING SYMPTOMS
regress usd_inpatient_ave1yr_cap_all i.cat_healthneed i.insurance i.cat_noinpatient i.SE_nonhealth [pw=fwt] //INPATIENT SPENDING PER POPULATION 
regress usd_outpatient_ave1mo_cap i.cat_healthneed i.insurance i.cat_pctzero_use i.SE_nonhealth [pw=fwt] //OUTPATIENT SPENDING PER POPULATION 
regress usd_health_exp_1yr_hh_cap i.cat_healthneed i.insurance i.cat_pctzero_use i.SE_nonhealth [pw=fwt] // ALL OOP HEALTH SPENDING PER POPULATION

*LOOK SEPARATELY AT CLAIMS, BECUASE IT INVOLVES ONLY KABUPATEN LEVEL DATA, NOT INDIVIDUAL DATA
use "$data/district/all_nomaps_kab", clear
regress usd_bpjs_claim_total_realpc i.cat_healthneed // INSURANCE CLAIMS PER POPULATION, TOTAL
regress usd_bpjs_claim_in_realpc i.cat_healthneed // INSURANCE CLAIMS PER POPULATION, INPATIENT
regress usd_bpjs_claim_out_realpc i.cat_healthneed // INSURANCE CLAIMS PER POPULATION, OUTPATIENT
regress usd_bpjs_claim_total_pc i.cat_healthneed // INSURANCE CLAIMS PER JKN PARTICIPANT, TOTAL
regress usd_bpjs_claim_in_pc i.cat_healthneed // INSURANCE CLAIMS PER JKN PARTICIPANT, INPATIENT
regress usd_bpjs_claim_out_pc i.cat_healthneed // INSURANCE CLAIMS PER JKN PARTICIPANT, OUTPATIENT

*ADD MEASURES OF ACCESS. USING CLAIMS PER INSURED CAPITA (BPJS REPORTS) TO CONTROL FOR DIFFERENCES IN COVERAGE
regress usd_bpjs_claim_in_pc i.cat_healthneed i.cat_noinpatient // INSURANCE CLAIMS PER REGISTERED JKN PARTICIPANT, INPATIENT
gen bpjs_out_monthly = usd_bpjs_claim_out_pc/12
regress bpjs_out_monthly i.cat_healthneed i.cat_pctzero_use // INSURANCE CLAIMS PER REGISTERED JKN PARTICIPANT, OUTPATIENT -- AVE MONTHLY SPENDING
regress usd_bpjs_claim_total_pc i.cat_healthneed i.cat_pctzero_use // INSURANCE CLAIMS PER REGISTERED JKN PARTICIPANT, TOTAL


***************************
*RADAR GRAPH: EQUITY
***************************

clear
use "$data/region/all_nomaps_reg.dta"
*NOTE: OOP MEASURE IS MEDIAN; have included bpjs claims by insured person and by capita population; spiderweb uses former
list region  ipkm_healthneed podes_access_binary health_exp_ave1mo_cap bpjs_claim_total_pc bpjs_claim_total_realpc

*MEAN
clear
use "$data/hh/susenas_2018.dta",clear

tabstat insurance treat_any health_exp_ave1mo_cap [aw=wert], by (region)

*MEDIAN
tabstat health_exp_ave1mo_cap [aw=wert], s(p50) by (region) f(%9.0fc)

***************************
*SUPPLEMENTARY FIGURE C. RADAR GRAPH:  INPATIENT ONLY
***************************
*NOTE THAT BECAUSE OF DIFFERENT WEIGHTING, LOOK SEPARATELY AT THOSE INDICATORS CALCULATED AT KAB LEVEL
clear
use "$data/region/all_nomaps_reg.dta"
*NOTE: OOP MEASURE IS MEDIAN
list region ipkm_healthneed insurance podes_inpatientaccess usd_bpjs_claim_in_pc, noobs

clear
use "$data/hh/susenas_2018.dta",clear
tabstat inpatient_1yr usd_inpatient_ave1yr_cap_all  [aw=wert], s(mean) by (region)

log close

